package com.scau.controller;

import com.scau.common.message.ResponseMessage;
import com.scau.common.util.MessageUtil;
import com.scau.entity.Contract;
import com.scau.entity.Counselor;
import com.scau.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 合同
 */
@RestController
@RequestMapping("contracts")
public class ContractController {

    @Autowired
    private ContractService contractService;

    @RequestMapping(method = RequestMethod.POST)
    public ResponseMessage<Contract> create(@RequestBody Contract contract) {

        contractService.add(contract);

        return MessageUtil.getSuccessMessage(contract);
    }

    /**
     * 按Id查询
     *
     * @param contractId
     * @return
     */
    @RequestMapping(value = "/{contractId}", method = RequestMethod.GET)
    public ResponseMessage<Counselor> get(@PathVariable Long contractId) {

        Contract contract = contractService.findOne(contractId);

        return MessageUtil.getSuccessMessage(contract);
    }

    /**
     * 按条件查询
     *
     * @param contract
     * @param pageable
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseMessage<Page<Contract>> list(Contract contract, Pageable pageable) {

        Page<Contract> contracts = contractService.findAll(contract, pageable);

        return MessageUtil.getSuccessMessage(contracts);
    }

}
